<?php
class Admin_contact_model extends model
{
	function __construct()
	{
		parent::__construct();	
	}
	
	function getAllResult()
	{
		
		$query = $this->db->get('bur_admin_emails');
		return $query->result();
	}
	
	function updateContact()
	{
		
		for($i =1; $i < 6;$i++)
		{
			$email =  $this->input->post('email'.$i);
			$arr = array('email_address' => $email);
			$this->db->where('admin_email_id',$i);
			$this->db->update('bur_admin_emails',$arr);
		}
	}
	
	function getAdminEmail()
	{
		$this->load->database();
		$query = $this->db->get('bur_admin_emails');
		$arr = array();
		if($query->num_rows > 0)
		{
			foreach($query->result() as $rows)
			{
				if($rows->email_address != '')
				{
					array_push($arr, $rows->email_address);
				}
			}
		}
		return $arr;
	}
    
    function send_contact_email($name,$company,$telephone,$email,$message)
    {
    	$config = array(
    		'mailtype'=>'html'
        );
        $data = array(                              
            'name'=> $name,
            'company' => $company,
            'telephone' => $telephone,
            'email' => $email,
            'message' => $message
        );
        
        $email_content = $this->load->view(TEMPLATE_NAME.'/front/mail/contact_us',$data, true);
        
        $this->load->library('email');
        $this->email->initialize($config);
        $this->email->from('noreply@mykprisguide.com', NOREPLY_ADD);
        $this->email->to($this->getAdminEmail());
        
        $this->email->reply_to('noreply@mykprisguide.com', NOREPLY_ADD);
              
        $this->email->subject('Contact Message');
        $this->email->message($email_content);                
        $this->email->send();
        return true;	
  }
}	
?>